﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Text;
using System.Net;

namespace Kgb.Web.Util
{
    public class RequestMethod
    {
        public WebRequest getRequest(string method, string contentType, string endPoint, string content)
        {
            var request = this.getRequest(method, contentType, endPoint);
            var dataArray = Encoding.UTF8.GetBytes(content.ToString());
            request.ContentLength = dataArray.Length;
            var requestStream = request.GetRequestStream();
            requestStream.Write(dataArray, 0, dataArray.Length);
            requestStream.Flush();
            requestStream.Close();

            return request;
        }

        public WebRequest getRequest(string method, string contentType, string endPoint)
        {
            var request = WebRequest.Create(endPoint);
            request.Method = method;
            request.ContentType = contentType;

            return request;
        }

        public Stream GetResponseStream(WebResponse response)
        {

            return response.GetResponseStream();

        }

        public StreamReader GetResponseReader(WebResponse response)
        {
            return new StreamReader(GetResponseStream(response));

        }

        public string unPackResponse(WebResponse response)
        {
            return GetResponseReader(response).ReadToEnd();
        }
    }
}